package com.cyx.exercise.ollama;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Ollama客户端配置类
 */
@Configuration
@ConfigurationProperties(prefix = "ollama")
public class OllamaConfig {
    
    private String baseUrl = "http://localhost:11434";
    private String defaultModel = "llama2";
    private int connectTimeoutSeconds = 30;
    private int readTimeoutSeconds = 300;
    private boolean useModernClient = true; // true使用HttpClient，false使用URLConnection
    
    /**
     * 创建Ollama客户端Bean
     */
    @Bean
    public OllamaClient ollamaClient() {
        return new OllamaClient(baseUrl);
    }
    
    /**
     * 创建传统Ollama客户端Bean
     */
    @Bean
    public OllamaClientLegacy ollamaClientLegacy() {
        return new OllamaClientLegacy(baseUrl, connectTimeoutSeconds * 1000, readTimeoutSeconds * 1000);
    }
    
    // Getters and Setters
    
    public String getBaseUrl() {
        return baseUrl;
    }
    
    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
    
    public String getDefaultModel() {
        return defaultModel;
    }
    
    public void setDefaultModel(String defaultModel) {
        this.defaultModel = defaultModel;
    }
    
    public int getConnectTimeoutSeconds() {
        return connectTimeoutSeconds;
    }
    
    public void setConnectTimeoutSeconds(int connectTimeoutSeconds) {
        this.connectTimeoutSeconds = connectTimeoutSeconds;
    }
    
    public int getReadTimeoutSeconds() {
        return readTimeoutSeconds;
    }
    
    public void setReadTimeoutSeconds(int readTimeoutSeconds) {
        this.readTimeoutSeconds = readTimeoutSeconds;
    }
    
    public boolean isUseModernClient() {
        return useModernClient;
    }
    
    public void setUseModernClient(boolean useModernClient) {
        this.useModernClient = useModernClient;
    }
    
    @Override
    public String toString() {
        return "OllamaConfig{" +
                "baseUrl='" + baseUrl + '\'' +
                ", defaultModel='" + defaultModel + '\'' +
                ", connectTimeoutSeconds=" + connectTimeoutSeconds +
                ", readTimeoutSeconds=" + readTimeoutSeconds +
                ", useModernClient=" + useModernClient +
                '}';
    }
}
